package com.jketing.spring.mvc.databind;

import javax.servlet.ServletRequest;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.web.servlet.mvc.method.annotation.ExtendedServletRequestDataBinder;

/**
 * EmptyStringToNullRequestDataBinder 
 * 
 * 空字符串转为null请求数据绑定器
 * 
 * @author  李荣华
 * @version v1.0
 * @date    2017-11-14
 * @Spring   4.3.8
 */
public class EmptyStringToNullRequestDataBinder extends ExtendedServletRequestDataBinder {
	
    public EmptyStringToNullRequestDataBinder(Object target, String objectName) {
        super(target, objectName);
    }

    protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
        super.addBindValues(mpvs, request);
        for (PropertyValue propertyValue : mpvs.getPropertyValueList()) {
            if (propertyValue.getValue().equals(""))
                propertyValue.setConvertedValue(null);
        }
    }
}
